
import controlP5.*;

ControlP5 cp5;
Textarea myTextarea1;
Textarea myTextarea2;



void setup() {
  size(945,538);
  
  cp5 = new ControlP5(this);
  
  myTextarea1 = cp5.addTextarea("txt")
                  .setPosition(900,10)
                  .setSize(30,30)
                  .setFont(createFont("arial",12))
                  .setLineHeight(14)
                  .setColor(color(0))
                  .setColorBackground(color(255,100))
                  .setColorForeground(color(255,100));
   myTextarea1.setText(0+"");
   
   myTextarea2 = cp5.addTextarea("score")
                  .setPosition(900,50)
                  .setSize(50,30)
                  .setFont(createFont("arial",12))
                  .setLineHeight(14)
                  .setColor(color(0))
                  .setColorBackground(color(255,100))
                  .setColorForeground(color(255,100));
  myTextarea2.setText("score");
  //-------------------------------- button to add score when the user said a right answer
   cp5.addButton("triple")
     .setPosition(120,500)
     .setSize(80,40)
     .getCaptionLabel().align(ControlP5.CENTER, ControlP5.CENTER)
     ; 
     cp5.addButton("once")
     .setPosition(230,500)
     .setSize(80,40)
     .getCaptionLabel().align(ControlP5.CENTER, ControlP5.CENTER)
     ; 
}
void draw() {
  background(125);
  fill(125);
}
public void incScore(){
  String name = cp5.get(Textarea.class,"txt").getText();
  int i = Integer.parseInt(name);
  i = i + 1;
  cp5.get(Textarea.class,"txt").setText(i+"");
}
public void updateScore(){
  String name = cp5.get(Textarea.class,"txt").getText();
  int i = Integer.parseInt(name);
  i = i + 5;
  cp5.get(Textarea.class,"txt").setText(i+"");
}
void controlEvent(ControlEvent theEvent) {
  if(theEvent.isController()) {
     if(theEvent.controller().name()=="triple") {
     updateScore();
    }
    if(theEvent.controller().name()=="once") {
     incScore();
    }
  }
}
